import socket

def run():
    host = '127.0.0.1'
    port = 5000
    
    print "Client initiates communication..."
    s = socket.socket()
    s.connect((host, port))
    
    message = ''
    
    while message != 'q':
        message = raw_input()
        s.send(message)
        print 'from client to server : ' + message
        data = s.recv(1024)
        print 'Received from server : ' + str(data)
    s.close()
    
def runUDP():
    host = '127.0.0.1'
    port = 5001
    
    server = ('127.0.0.1', 5000)
    
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((host, port))
    
    message = ''
    while message != 'q':
        message = raw_input("-> ")
        s.sendto(message, server)
        data, adr = s.recvfrom(1024)
        print "Received from server : " + str(adr) + 'data -> ' + str(data)
    s.close()
    
def main():
    runUDP()
    
if __name__ == '__main__':
    main()